<%@page import="itsm.isperp.framework.core.context.ContextHolder"%><%@ page
	language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
  String path = request.getContextPath();
			String basePath = ContextHolder.getWebServerName(request);
%>


<div data-role="content" class="ui-content" role="main">


	<form method="post"
		action="<%=basePath%>api/wechat/setting/register2_3">
		<input type="hidden" name="openid" value="${openid}" />
		<div class="box" style="background-color:#f8f8f8">
			<div class="weui-cell " style="background-color:white">
				<div class="weui-cell__hd">
					<label class="weui-label"><span class="starReq">*</span>单位</label>
				</div>
				<div class="weui-cell__bd weui-cell_primary">
					<input name="cusCustomerId" id="cusCustomerId" style="display:none">
					<input id="cusName" name="cusName" class="weui-input formRequired"
						data-valid="单位" type="text" onfocus="cusfocus()"
						placeholder="请输入您的单位">
				</div>
				<div class="weui-cell_ft" style="display: none">
					<i class="weui_icon_warn"></i>
				</div>
			</div>

			<div class="weui-skin_android" id="androidActionsheet"
				style="display: none">
				<div class="weui-mask"></div>
				<div class="weui-actionsheet" style="height:80%;">
					<div class="weui-actionsheet__menu"
						style="overflow:auto;height:100%;"></div>
				</div>
			</div>


			<div class="weui-cell " style="background-color:white">
				<div class="weui-cell__hd">
					<label class="weui-label"><span class="starReq">*</span>姓名</label>
				</div>
				<div class="weui-cell__bd weui-cell_primary">
					<input id="name" name="name" class="weui-input formRequired"
						data-valid="姓名" type="text" placeholder="请输入姓名">
				</div>
				<div class="weui-cell_ft" style="display: none">
					<i class="weui_icon_warn"></i>
				</div>
			</div>

			<div class="weui-cell" style="background-color:white">
				<div class="weui-cell__hd">
					<label class="weui-label"><span class="starReq">*</span>手机</label>
				</div>
				<div class="weui-cell__bd weui-cell_primary">
					<input id="mobile" name="mobile" class="weui-input formRequired"
						data-valid="手机" type="text" placeholder="请输入手机">
				</div>
				<div class="weui-cell_ft" style="display: none">
					<i class="weui_icon_warn"></i>
				</div>
			</div>

			<div class="weui-cells__title">
				<span class="starReq">*</span>生日
			</div>

			<div class="weui-cells">
				<div class="weui-cell weui-cell_select weui-cell_select-after">
					<div class="weui-cell__hd">
						<label for="" class="weui-label">月</label>
					</div>
					<div class="weui-cell__bd">
						<select id="idYear" style="display:none" name="idYear" data=""
							data-allow-empty="false" data-width="40px"></select> <select
							class="weui-select formRequired" id="idMonth" data-valid="出生月"
							name="birthdayMonth">

						</select>
					</div>
				</div>
				<div class="weui-cell weui-cell_select weui-cell_select-after">
					<div class="weui-cell__hd">
						<label for="" class="weui-label ">日</label>
					</div>
					<div class="weui-cell__bd">
						<select class="weui-select formRequired" id="idDay"
							name="birthdayDay" data-valid="出生日">

						</select>
					</div>
				</div>
			</div>

			<div class="weui-cells__title">更多</div>
			<div class="weui-cells weui-cells_form">
				<div class="weui-cell" style="background-color:white;">
					<div class="weui-cell__hd">
						<label class="weui-label">邮箱</label>
					</div>
					<div class="weui-cell__bd weui-cell_primary">
						<input id="email" name="" email"" class="weui-input " type="text"
							placeholder="请输入邮箱">
					</div>
					<div class="weui-cell_ft" style="display: none">
						<i class="weui_icon_warn"></i>
					</div>
				</div>
			</div>
			<div class="weui-cell " style="background-color:white">
				<div class="weui-cell__hd">
					<label class="weui-label">联系地址</label>
				</div>
				<div class="weui-cell__bd weui-cell_primary">
					<input id="address" name="address" " class="weui-input "
						type="text" placeholder="请输入联系地址">
				</div>
				<div class="weui-cell_ft" style="display: none">
					<i class="weui_icon_warn"></i>
				</div>
			</div>



			<div>
				<button class="weui-btn weui-btn_primary" type="submit"
					onclick="return takeSubmit();">提交</button>
			</div>

		</div>

	</form>
	<div id="loadingToast" style="opacity: 0; display: none;">
		<div class="weui-mask_transparent"></div>
		<div class="weui-toast">
			<i class="weui-loading weui-icon_toast"></i>
			<p class="weui-toast__content">数据加载中</p>
		</div>
	</div>

	<script type="text/javascript">
	document.title="填写基本信息";
	$(function() {
	    var $searchBar = $('#searchBar'), $searchResult = $('#searchResult'), $searchText = $('#searchText'), $searchInput = $('#searchInput'), $searchClear = $('#searchClear'), $searchOk = $('#searchOk');
	    $searchBar.addClass('weui-search-bar_focusing');
	    $searchInput.focus();
	    function hideSearchResult() {
		$searchResult.hide();
		$searchInput.val('');
	    }
	    function cancelSearch() {
		hideSearchResult();
		$searchBar.removeClass('weui-search-bar_focusing');
		$searchText.show();
	    }

	    $searchText.on('click', function() {

	    });
	    $searchInput.on('blur', function() {
		/* if (!this.value.length)
			cancelSearch(); */
	    }).on('input', function() {
		search(this.value)
	    });
	    $searchClear.on('click', function() {
		hideSearchResult();
		$searchInput.focus();
	    });
	    $searchOk.on('click', function() {

		$("#search-weui-mask").hide();
		$("body").css("overflow", "auto");
		$("#searchResult").html("");

		if ($("#searchInput").val() != "") {
		    $("#cusName").val($("#searchInput").val());
		}
		$("#cusCustomerId").val("");

		$("#searchInput").val("");
	    });
	});

	function search(v) {
	    if (v.length) {

		//实时搜索单位

		var url = "autocompleteList?term=" + v;

		$
			.ajax({
			    url : url,
			    success : function(data) {
				$("#searchResult").html("");

				if (data.content.length > 0) {
				    for ( var i = 0; i < data.content.length; i++) {
					var andmenu = $("#searchResult");
					andmenu
						.append("<div class=\"weui-cell weui-cell_access\" onclick=\"choseCustomer('"
							+ data.content[i].id
							+ "','"
							+ data.content[i].name
							+ "')\">"
							+ "<div class=\"weui-cell__bd weui-cell_primary\"><p>"
							+ data.content[i].name
							+ "</p></div>"
							+ "</div>");
				    }

				}
			    }
			});

		$("#searchResult").show();
	    } else {
		$("#searchResult").hide();
	    }
	}
    </script>
	<script>
	var subing = false;
	function takeSubmit() {
	    var validReult = true;
	    var message = "请填写：";

	    $("form .formRequired")
		    .each(
			    function(index, item) {
				var me = $(item);
				var t = me.is("input:checkbox")
					|| me.is("input:radio"), tValue = "";
				if (t) {
				    var tName = me.attr("name");
				    tValue = me.find(
					    "input[name='" + tName
						    + "']:checked").val();
				} else {
				    tValue = me.val();
				}

				if ((tValue == "" || tValue == undefined)) {

				    message += "" + me.data("valid") + "、";
				    validReult = false;
				}
			    });

	    //salert(message.length);

	    message = message.substring(0, message.length - 1);

	    if (!validReult) {
		$.weui.alert({
		    text : message
		});
		return false;
	    }

	    if (subing == false) {
		$(this).hide();
		var $loadingToast = $('#loadingToast');
		if ($loadingToast.css('display') != 'none')
		    return;
		$loadingToast.fadeIn(100);
		subing = true;
		$("#formid").submit();
		return true;
	    }

	}

	var myDate = new Date();
	$("#dateSelector").DateSelector({
	    ctlYearId : 'idYear',
	    ctlMonthId : 'idMonth',
	    defYear : 2000,
	    defMonth : 1,
	    defDay : 1,
	    ctlDayId : 'idDay',
	    minYear : 2000,
	    maxYear : 2100
	});

	$("#idMonth").val("");
	$("#idDay").val("");

	var lastInputCus = "";

	function cusfocus() {
	    $("#searchInput").val($("#cusName").val());
	    $("body").css("overflow", "hidden");
	    $("#search-weui-mask").show();
	    search($("#cusName").val());
	    $("#searchInput").focus();

	}

	function cusblur() {
	    var v = $("#cusName").val();

	    if (v != "" && (lastInputCus != v)) {
		lastInputCus = v;
		var url = "autocompleteList?term=" + v;

		$
			.ajax({
			    url : url,
			    success : function(data) {
				$(".weui-actionsheet__menu").html("");
				if (data.content.length > 1) {

				    for ( var i = 0; i < data.content.length; i++) {
					var andmenu = $(".weui-actionsheet__menu");
					andmenu
						.append("<div class=\"weui-actionsheet__cell\" onclick=\"choseCustomer('"
							+ data.content[i].id
							+ "','"
							+ data.content[i].name
							+ "')\">"
							+ data.content[i].name
							+ "</div>");
				    }
				    var $androidActionSheet = $('#androidActionsheet');
				    $androidActionSheet.fadeIn(200);
				    var $androidMask = $androidActionSheet
					    .find('.weui-mask');
				    $androidMask.on('click', function() {
					$androidActionSheet.fadeOut(100);
				    });
				} else if (data.content.length == 1) {
				    $("#cusCustomerId").val(data.content[0].id);
				    $("#cusName").val(data.content[0].name);
				}
			    }
			});

	    } else {
		lastInputCus = v;
	    }
	}
	function choseCustomer(id, name) {
	    $("#cusCustomerId").val(id);
	    $("#cusName").val(name);
	    $("#search-weui-mask").hide();
	    $("body").css("overflow", "auto");
	    $("#searchResult").html("");
	    $("#searchInput").val("");
	}
    </script>

</div>
